﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Elements
{
    /// <summary>
    /// 形状基类
    /// </summary>
    public abstract class ShapeBaseV2
    {
        //注：文章中说明：暂时以这4个为主。
        
        /// <summary>
        /// 连接点
        /// </summary>
        public enum ShapeLinkPoints
        {
            左,
            上,
            右,
            下,
        }
        /// <summary>
        /// 形状ID
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 形状位置和尺寸
        /// </summary>
        public Rectangle Rect { get; set; }
        /// <summary>
        /// 背景颜色
        /// </summary>
        public Color BackgroundColor { get; set; }
        /// <summary>
        /// 形状内的文本
        /// </summary>
        public string Text { get; set; }
        /// <summary>
        /// 文本字体
        /// </summary>
        public Font TextFont { get; set; }
        /// <summary>
        /// 文本颜色
        /// </summary>
        public Color FontColor { get; set; }

        /// <summary>
        /// 绘制形状
        /// </summary>
        /// <param name="g"></param>
        public abstract void Draw(Graphics g);

        /// <summary>
        /// 获取连接点坐标
        /// </summary>
        /// <param name="linkPoint"></param>
        /// <returns></returns>
        public virtual Point GetLinkPoint(ShapeLinkPoints linkPoint)
        {
            //默认实现以矩形为基础，取矩形四边中点坐标。

            int ptX = 0;
            int ptY = 0;
            switch (linkPoint)
            {
                case ShapeLinkPoints.左:
                    ptX = Rect.X;
                    ptY = Rect.Y + Rect.Height / 2;
                    break;
                case ShapeLinkPoints.上:
                    ptX = Rect.X + Rect.Width / 2;
                    ptY = Rect.Y;
                    break;
                case ShapeLinkPoints.右:
                    ptX=Rect.X + Rect.Width;
                    ptY = Rect.Y + Rect.Height / 2;
                    break;
                case ShapeLinkPoints.下:
                default:
                    ptX = Rect.X + Rect.Width / 2;
                    ptY = Rect.Y + Rect.Height;
                    break;
            }
            return new Point(ptX, ptY);
        }
    }
}
